var subProjectStore = null;
var gridStoreg = null;
Ext
		.define(
				'component.marketing.rgPanel',
				{
					extend : 'Ext.form.Panel',
					initComponent : function() {
						// 项目
						subProjectStore = new Ext.data.Store(
								{
									singleton : true,
									autoDestroy : true,
									fields : [ "id", "projectName" ],
									proxy : {
										type : 'ajax',
										url : contextPath
												+ '/estate/project/findProjectList?resourcesCode=menu_0003_0001',
										reader : {
											type : 'json',
											root : 'root' // 数据
										}
									},
									autoLoad : false
								});
						subProjectStore
								.load({
									callback : function(records, options,
											success) {
										var count = subProjectStore.getCount();
										if (count > 0) {
											var id = subProjectStore.getAt(0)
													.get("id");
											Ext.getCmp('subProjectStore')
													.setValue(id)
											if(Ext.Array.contains(idata,"marketing:list:all")){
												var data = {"projectName": "全部", "id": '-1'};
												var rs = Ext.create(data);
												subProjectStore.insert(count+1, rs);
											}
										}
									}
								});

						var formg = Ext
								.create(
										"Ext.form.Panel",
										{
											minHeight : 170,
											title : "查询条件",
											collapsible : true, // 可折叠
											autoScroll : false, // 自动创建滚动条
											defaultType : 'textfield',
											defaults : {
												anchor : '100%'
											},
											fieldDefaults : {
												margin : 2,
												labelWidth : 80,
												labelAlign : "right",
												margin : "5 0 0 0"
											},
											items : [
													{
														xtype : "container",
														layout : "hbox",
														items : [ {
															xtype : "container",
															layout : "hbox",
															items : [
																	{
																		xtype : 'combobox',
																		id : 'subProjectStore',
																		name : "projectId",
																		store : subProjectStore,
																		valueField : "id",
																		displayField : "projectName",
																		fieldLabel : '所属项目',
																		queryMode : 'local',
																		typeAhead : true,
																		editable : false
																	},
																	{
																		xtype : "textfield",
																		name : "customerName",
																		fieldLabel : "客户名称"
																	} ]
														} ]
													},
													{
														xtype : "container",
														layout : "hbox",
														items : [
																{
																	xtype : "textfield",
																	name : "resourcesCode",
																	value : resourcesCode,
																	hidden : true
																},
																{
																	xtype : "textfield",
																	name : "resourcesName",
																	value : "resName_pin_list",
																	hidden : true
																},
																{
																	xtype : "textfield",
																	name : "mobile",
																	fieldLabel : "客户电话"
																},
																{
																	xtype : "textfield",
																	name : "agentName",
																	fieldLabel : "经纪人"
																},
																{
																	fieldLabel : "逾期未签约",
																	xtype : "combo",
																	name : "isOverdue",
																	displayField : 'name',
																	valueField : 'value',
																	mode : "local",
																	store : new Ext.data.Store(
																			{
																				fields : [
																						'value',
																						'name' ],
																				data : [
																						{
																							"value" : "",
																							"name" : "全部"
																						},
																						{
																							"value" : ">",
																							"name" : "是"
																						},
																						{
																							"value" : "<=",
																							"name" : "否"
																						} ]
																			})
																} ]
													},
													{
														xtype : "container",
														layout : "hbox",
														items : [
																{
																	xtype : "textfield",
																	name : "combinedName",
																	fieldLabel : "房号"
																},
																{
																	xtype : "datefield",
																	name : "didTimeBefore",
																	fieldLabel : "认购日期",
																	format : 'Y-m-d'
																},
																{
																	margin : "0 5 0 5",
																	xtype : 'displayfield',
																	value : '-'
																},
																{
																	xtype : "datefield",
																	name : "didTimeAfter",
																	format : 'Y-m-d'
																} ]
													},
													{
														xtype : "container",
														layout : "hbox",
														items : [ {
															xtype : "checkboxgroup",
															id : "ckStatusg",
															name : "m_auditStatus",
															fieldLabel : "审核状态",
															width : 450,
															items : [
																	{
																		boxLabel : '待提交',
																		inputValue : '0'
																	},
																	{
																		boxLabel : '审核中',
																		inputValue : '1'
																	},
																	{
																		boxLabel : '已通过',
																		inputValue : '3',
																		checked : true
																	},
																	{
																		boxLabel : '已退回',
																		inputValue : '2'
																	} ]
														} ]
													},
													{
														xtype : 'fieldset',
														title : '更多...',
														collapsible : true,
														collapsed : true,
														defaults : {
															labelWidth : 89,
															anchor : '100%',
															layout : {
																type : 'hbox',
																defaultMargins : {
																	top : 0,
																	right : 5,
																	bottom : 0,
																	left : 0
																}
															}
														},
														items : [
																{
																	xtype : "container",
																	layout : "hbox",
																	items : [
																			{
																				xtype : "textfield",
																				name : "resourcesCode",
																				value : resourcesCode,
																				hidden : true
																			},
																			{
																				xtype : "textfield",
																				name : "resourcesName",
																				value : "resName_pin_list",
																				hidden : true
																			},
																			{
																				xtype : "textfield",
																				name : "subscribeCode",
																				fieldLabel : "认购号"
																			} ]
																},
																{
																	xtype : "container",
																	layout : "hbox",
																	items : [
																			{
																				xtype : "datefield",
																				name : "dueTimeBefore",
																				fieldLabel : "转签约日期",
																				format : 'Y-m-d'
																			},
																			{
																				margin : "0 5 0 5",
																				xtype : 'displayfield',
																				value : '-'
																			},
																			{
																				xtype : "datefield",
																				name : "dueTimeAfter",
																				format : 'Y-m-d'
																			} ]
																},
																{
																	xtype : "container",
																	layout : "hbox",
																	items : [
																			{
																				xtype : "datefield",
																				name : "checkDateBefore",
																				fieldLabel : "审核日期",
																				format : 'Y-m-d'
																			},
																			{
																				margin : "0 5 0 5",
																				xtype : 'displayfield',
																				value : '-'
																			},
																			{
																				xtype : "datefield",
																				name : "checkDateAfter",
																				format : 'Y-m-d'
																			} ]
																},
																{
																	xtype : "container",
																	layout : "hbox",
																	items : [ {
																		xtype : "checkboxgroup",
																		id : "busStatusg",
																		fieldLabel : "业务状态",
																		name : "m_businessStatus",
																		width : 700,
																		items : [
																				{
																					boxLabel : '认购',
																					inputValue : '1'
																				},
																				{
																					boxLabel : '已换房',
																					inputValue : '3'
																				},
																				{
																					boxLabel : '认购转签约',
																					inputValue : '2'
																				},
																				{
																					boxLabel : '已更名',
																					inputValue : '4'
																				},
																				{
																					boxLabel : '退认购',
																					inputValue : '5'
																				},
																				{
																					boxLabel : '签约换房',
																					inputValue : '8'
																				},
																				{
																					boxLabel : '签约退房',
																					inputValue : '9'
																				}  ]
																	} ]
																} ]
													} ],
											buttons : [
													{
														xtype : "button",
														text : "查询",
														handler : function() {
															// 获取通过checkboxgroup定义的checkbox值
															// 审核状态
															var ckStatusValue = Ext
																	.getCmp(
																			'ckStatusg')
																	.getChecked();
															var ckStatus = "";
															Ext.Array
																	.each(
																			ckStatusValue,
																			function(
																					item) {
																				ckStatus += item.inputValue
																						+ ',';
																			});
															gridStoreg
																	.getProxy().extraParams.m_auditStatus = ckStatus;
															// 业务状态
															var busStatusValue = Ext
																	.getCmp(
																			'busStatusg')
																	.getChecked();
															var busStatus = "";
															Ext.Array
																	.each(
																			busStatusValue,
																			function(
																					item) {
																				busStatus += item.inputValue
																						+ ',';
																			});
															gridStoreg
																	.getProxy().extraParams.m_businessStatus = busStatus;
															// gridStoreg.load();
															var pagingTool = Ext
																	.getCmp("pagingToolg");
															pagingTool
																	.moveFirst();// 跳至第一页
														}
													},
													{
														xtype : "button",
														text : "清空",
														handler : function() {
															formg.getForm()
																	.reset();
														}
													},{
														xtype : "button",
														text : "批量导入",
														hidden: false,
														handler : function() {
															var selectProjectId = Ext.getCmp(
																	"subProjectStore").getValue();
															if (selectProjectId
																	&& selectProjectId == "-1") {
																Ext.MessageBox.alert("系统提示",
																		"请选择项目");
																return;
															}
															subscribeImport();
														}
													},
													{
														xtype : "button",
														text : "导出",
														hidden : businessChangeExport,
														handler : function() {
															var count = gridg
																	.getStore()
																	.getCount();
															if (count <= 0) {
																Ext.MessageBox
																		.alert(
																				"系统提示",
																				"没有可导出的数据");
															} else {
																var ckStatusValue = Ext
																		.getCmp(
																				'ckStatusg')
																		.getChecked();
																var ckStatus = "";
																Ext.Array
																		.each(
																				ckStatusValue,
																				function(
																						item) {
																					ckStatus += item.inputValue
																							+ ',';
																				});
																gridStoreg
																		.getProxy().extraParams.m_auditStatus = ckStatus;
																// 业务状态
																var busStatusValue = Ext
																		.getCmp(
																				'busStatusg')
																		.getChecked();
																var busStatus = "";
																Ext.Array
																		.each(
																				busStatusValue,
																				function(
																						item) {
																					busStatus += item.inputValue
																							+ ',';
																				});
																gridStoreg
																		.getProxy().extraParams.m_businessStatus = busStatus;
																var value = encodeURI(encodeURI(
																		JSON
																				.stringify(gridStoreg
																						.getProxy().extraParams),
																		"utf-8"));
																location.href = jypath
																		+ '/customer/subscribe/subscribeExport?value='
																		+ value;
															}

														}
													} ]
										});

						var statistics = Ext
								.create(
										'Ext.form.FormPanel',
										{
											items : [ {
												xtype : "fieldcontainer",
												layout : "hbox",
												items : [
														{
															xtype : "fieldcontainer",
															layout : "column",
															items : [
																	{
																		xtype : "displayfield",
																		value : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;共"
																	},
																	{
																		xtype : "displayfield",
																		name : "info_sumRoom",
																		value : "0"
																	},
																	{
																		xtype : "displayfield",
																		value : "套,&nbsp;&nbsp;&nbsp; "
																	} ]
														},
														{
															xtype : "fieldcontainer",
															layout : "column",
															items : [
																	{
																		xtype : "displayfield",
																		name : "info_calculateArea",
																		value : "0"
																	},
																	{
																		xtype : "displayfield",
																		value : "㎡,&nbsp;&nbsp;&nbsp; "
																	}, ]
														},
														{
															xtype : "fieldcontainer",
															layout : "column",
															items : [
																	{
																		xtype : "displayfield",
																		name : "info_Amount",
																		value : "0",
																		renderer : Ext.util.Format
																				.numberRenderer('0,000.00')
																	},
																	{
																		xtype : "displayfield",
																		value : "元"
																	}, ]
														} ]
											} ]
										});

						gridStoreg = Ext
								.create(
										'Ext.data.Store',
										{
											fields : [ "id", "subscribeDate",
													"customerName",
													"combinedName",
													"calculateArea",
													"roomStatus",
													"houseTypeName",
													"subscribeAmount",
													"depositReceivable",
													"userName", "userName",
													"businessStatus",
													"auditStatus",
													"totalRealAmount",
													"subscribePrice", "roomId",
													"overdueDay",
													"conversionSignDate" ],
											pageSize : 10, // 页容量5条数据
											// 是否在服务端排序 （true的话，在客户端就不能排序）
											remoteSort : false,
											proxy : {
												type : 'ajax',
												url : jypath
														+ '/customer/subscribe/list?iscustomerSub=1',
												actionMethods : {
													read : 'POST'
												},
												reader : { // 这里的reader为数据存储组织的地方，下面的配置是为json格式的数据，例如：[{"total":50,"rows":[{"a":"3","b":"4"}]}]
													type : 'json', // 返回数据类型为json格式
													root : 'rows', // 数据
													totalProperty : 'total' // 数据总条数
												}
											},
											autoLoad : true
										// 即时加载数据
										});

						gridStoreg
								.on(
										"beforeload",
										function() {
											Ext
													.apply(
															gridStoreg.proxy.extraParams,
															formg
																	.getForm()
																	.getValues());
											var projectId = Ext.getCmp(
													"subProjectStore")
													.getValue();
											if (projectId == "-1") {
												gridStoreg.proxy.extraParams.projectId = "";
											}
											//debugger
											var newResCode = resourcesCode;
											if(resourcesCode != "menu_0005_0005"){
												newResCode = resourcesCode + ",menu_0005_0005";
											}
											var ckStatusValue = Ext.getCmp(
													'ckStatusg').getChecked();
											var ckStatus = "";
											Ext.Array
													.each(
															ckStatusValue,
															function(item) {
																ckStatus += item.inputValue
																		+ ',';
															});
											gridStoreg.getProxy().extraParams.m_auditStatus = ckStatus;

											gridStoreg.proxy.extraParams.resourcesCode = newResCode;
										});

						Math.formatFloat = function(f, digit) {
							var m = Math.pow(100, digit);
							return parseInt(f * m, 10) / m;
						}

						gridStoreg
								.on(
										"load",
										function() {
											var subscribeAmount = 0;
											var calculateArea = 0;
											var rows = gridStoreg.getCount();
											for (var i = 0; i < rows; i++) {
												var rowData = gridStoreg
														.getAt(i).data;
												calculateArea += rowData.calculateArea;
												subscribeAmount += rowData.subscribeAmount;
											}
											statistics.getForm().findField(
													"info_sumRoom").setValue(
													rows);
											statistics
													.getForm()
													.findField(
															"info_calculateArea")
													.setValue(
															Math
																	.formatFloat(
																			calculateArea,
																			1));
											statistics
													.getForm()
													.findField("info_Amount")
													.setValue(
															Math
																	.formatFloat(
																			subscribeAmount,
																			1));
										});

						function onreload() {
							gridStoreg.on("beforeload", function() {
								Ext.apply(gridStoreg.proxy.extraParams, formg
										.getForm().getValues());
							});
						}

						var gridg = Ext
								.create(
										'Ext.grid.Panel',
										{
											minHeight : 600,
											store : gridStoreg,
											columnLines : true,
											columns : [
													{
														text : "操作",
														dataIndex : 'roomId',
														width : 300,
														locked : true,
														renderer : function(
																value,
																cellmeta,
																record,
																rowIndex,
																columnIndex,
																store) {
															var rec = gridg
																	.getStore()
																	.getAt(
																			rowIndex);
															// 查看

															var html = "";
															var timeStr = Ext.Date
																	.format(
																			new Date(
																					rec
																							.get('subscribeDate')),
																			'Y-m-d');
															/*if (!dataRepairSubscribeDelete) {
																html += "&emsp;<a href='javascript:deleteHoxfitSub("
																		+ rec
																				.get('id')
																		+ ")'>删除认购</a>";
															}*/
															if (!dataRepairSubscribeDate) {
																html += "&emsp;<a href='javascript:correctSub(\""
																		+ timeStr
																		+ "\","
																		+ rec.get('id')+ ")'>认购日期变更</a>";
															}
															html += "&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:parent.openMenu(\"0\",\""
																	+ rec.get('id')+ "\",\"\",\"认购详情\",\"/customer/subscribe/toView?id=" + rec.get('id')+ "&returnUrl=,marketing,pin,index\")' style='cursor:pointer'>查看</a>";
															if (rec
																	.get('auditStatus') == 0
																	|| rec
																			.get('auditStatus') == 2) {
																// 房间为认购状态，可编辑
																if (rec
																		.get("roomStatus") == 4
																		|| rec
																				.get("roomStatus") == 1) {
																	html += "&emsp;<a href='" + jypath + "/customer/subscribe/toEdit?id=" + rec.get('id') + "&returnUrl=,marketing,pin,index' style='cursor:pointer'>编辑</a>";
																}
																// 审核状态为待提交时，可编辑
																if (!dataRepairSubscribeDelete && rec.get('auditStatus') == 0) {
																	html += "&emsp;<a href='javascript:deleteHoxfitSub("+ rec.get('id')+ ")'>删除认购</a>";
																}
															}
															return html;
														}
													},
													{
														text : '认购日期',
														dataIndex : 'subscribeDate',
														renderer : function(
																value) {
															return Ext.Date
																	.format(
																			new Date(
																					value),
																			'Y-m-d')
														}
													},
													{
														text : '客户名称',
														dataIndex : 'customerName'
													},
													{
														text : '房号',
														dataIndex : 'combinedName',
														width : 250,
														renderer : function(
																value,
																cellmeta,
																record,
																rowIndex,
																columnIndex,
																store) {

															var rec = gridg
																	.getStore()
																	.getAt(
																			rowIndex);
															var roomId = rec
																	.get('roomId');
															if (roomId != null) {
																return "<a style='text-decoration:none;' href='javascript:openWindow("
																		+ roomId
																		+ ")'>"
																		+ value
																		+ "</a>";
															}
															return value;
														}
													},
													{
														text : '户型',
														dataIndex : 'houseTypeName',
														renderer : function(val) {
															if (val == 0) {
																return '正常';
															} else if (val == 1) {
																return '已关闭';
															}
															return val;
														}
													},
													{
														text : '计价面积(平方米)',
														dataIndex : 'calculateArea'
													},
													{
														text : '签约单价(元)',
														dataIndex : 'subscribePrice',
														renderer : Ext.util.Format
																.numberRenderer('0,000.00')
													},
													{
														text : '合同金额(元)',
														dataIndex : 'subscribeAmount',
														renderer : Ext.util.Format
																.numberRenderer('0,000.00')
													},
													{
														text : '转签约日期',
														dataIndex : 'conversionSignDate',
														renderer : function(
																value) {
															return Ext.Date
																	.format(
																			new Date(
																					value),
																			'Y-m-d')
														}
													},
													{
														text : '是否逾期未转签约',
														dataIndex : 'overdueDay',
														renderer : function(val) {
															if (val > 0) {
																return '是';
															} else {
																return '否';
															}
														}
													},
													{
														text : '逾期天数',
														dataIndex : 'overdueDay',
														renderer : function(val) {
															if (val > 0) {
																return val;
															} else {
																return '';
															}
														}
													},
													{
														text : '认购金(元)',
														dataIndex : 'depositReceivable',
														renderer : Ext.util.Format
																.numberRenderer('0,000.00')
													},
													{
														text : '已收认购金(元)',
														dataIndex : 'totalRealAmount',
														renderer : function(
																value) {
															if (value == null
																	|| value == "") {
																return "0.00";
															}
															return Ext.util.Format
																	.number(
																			value,
																			'0,000.00');
														}
													},
													{
														text : '经纪人',
														dataIndex : 'userName'
													},
													{
														text : '业务状态',
														dataIndex : 'businessStatus',
														renderer : function(val) {
															if (val == 1) {
																return '认购';
															} else if (val == 3) {
																return '已换房';
															} else if (val == 2) {
																return '认购转签约';
															} else if (val == 4) {
																return '已更名';
															} else if (val == 5) {
																return '退认购';
															} else if (val == 6) {
																return '延期签约';
															}
															return val;
														}
													},
													{
														text : '审核状态',
														dataIndex : 'auditStatus',
														renderer : function(val) {
															if (val == 0) {
																return '待提交';
															} else if (val == 1) {
																return '审核中';
															} else if (val == 2) {
																return '已退回';
															} else if (val == 3) {
																return '已通过';
															}
															return val;
														}
													}],
											title : '认购列表',
											dockedItems : [ {
												xtype : 'pagingtoolbar',
												store : gridStoreg, // GridPanel中使用的数据  
												dock : 'bottom',
												displayInfo : true,
												emptyMsg : "没有数据",
												displayMsg : "显示从{0}条数据到{1}条数据，共{2}条数据",
												id : 'pagingToolg'
											} ]
										});

						var defaultConfigg = {
							defaults : {
								split : true, //有分割线  
								collapsible : true
							//可以折叠
							},
							items : [ formg, statistics, gridg ]
						};
						Ext.apply(this, defaultConfigg);
						this.callParent(arguments);
					}
				});

function correctSub(subscribeDate, id) {
	var fromPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		defaultType : 'textfield',
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [ {
			xtype : "datefield",
			fieldLabel : "认购日期",
			format : 'Y-m-d',
			id : 'newSubTimeValue',
			value : subscribeDate
		} ]
	});

	var window = Ext.create('Ext.Window', {
		title : "修正数据",
		width : 300,
		closable : true,
		modal : true,
		headerPosition : 'top',
		items : [ fromPanel ],
		buttons : [ {
			xtype : "button",
			text : "确定",
			iconCls : 'icon-save',
			handler : function() {
				var newSubTime = Ext.Date.format(new Date(Ext.getCmp(
						"newSubTimeValue").getValue()), 'Y-m-d');
				Ext.Ajax.request({
					url : jypath + '/hoxfit/updateSubDate',
					params : {
						subId : id,
						subDate : newSubTime
					},
					method : 'POST',
					callback : function(options, success, response) {
						if (success) {
							var obj = eval('(' + response.responseText + ')');
							if (obj.res == "1") {
								Ext.MessageBox.alert("系统提示", "修正认购记录成功");
								gridStoreg.load();
							} else if (obj.res == "100") {
								Ext.MessageBox.alert("系统提示", "该账号没有修复权限");
							}
							window.close();
						} else {
							Ext.MessageBox.alert("系统提示", "修正认购记录失败！");
						}
					}
				});

			}
		} ]

	});
	window.show();
}

function delGou(id) {
	Ext.MessageBox.confirm("提示", "是否删除该认购记录?", function(btn, txt) {
		if (btn == "yes") {
			Ext.Ajax.request({
				url : jypath + '/customer/subscribe/delete',
				params : {
					id : id
				},
				method : 'POST',
				callback : function(options, success, response) {
					if (success) {
						var obj = eval('(' + response.responseText + ')');
						if (obj.res == '100') {
							Ext.MessageBox.alert("系统提示", "该账号没有删除权限");
						} else {
							Ext.MessageBox.alert("系统提示", "删除认购记录成功");
							gridStoreg.load();
						}
					} else {
						Ext.MessageBox.alert("系统提示", "删除认购记录失败！");
					}
				}
			});
		}
	});
}

function deleteHoxfitSub(id) {
	Ext.MessageBox.confirm("提示", "是否删除该认购记录?", function(btn, txt) {
		if (btn == "yes") {
			Ext.Ajax.request({
				url : jypath + '/hoxfit/subscribeDeleteHotfix',
				params : {
					subId : id
				},
				method : 'POST',
				callback : function(options, success, response) {
					if (success) {
						var obj = eval('(' + response.responseText + ')');
						if (obj.res == '100') {
							Ext.MessageBox.alert("系统提示", "该账号没有删除权限");
						} else {
							Ext.MessageBox.alert("系统提示", "删除认购记录成功");
							gridStoreg.load();
						}
					} else {
						Ext.MessageBox.alert("系统提示", "删除认购记录失败！");
					}
				}
			});
		}
	});
}

function subscribeImport(){
	var fromPanel = Ext.create("Ext.form.Panel", {
		collapsible : false,
		autoScroll : false,
		defaultType : 'textfield',
		defaults : {
			anchor : '100%'
		},
		fieldDefaults : {
			flex : 1
		},
		items : [{
			fieldLabel : "导入类型",
			xtype : "combo",
			id: "type",
			name : "type",
			displayField : 'name',
			valueField : 'value',
			mode : "local",
			anchor : '95%',
			value: '1',
			store : new Ext.data.Store({
				fields : ['value', 'name'],
				data : [{
					"value": "1",
					"name": "通用"
				}, {
					"value": "2",
					"name": "车位"
				}]
			})
		}, {
			xtype : 'filefield',
			fieldLabel : '导入excel',
			emptyText : '请上传excel文件',
			id : 'multipartFile',
			name : 'multipartFile',
			msgTarget : 'side',
			allowBlank : false,
			anchor : '95%',
			buttonConfig : {
				iconCls : 'silk-folder'
			},
			buttonText : '选择文件'
		}]
	});

	var window = Ext.create('Ext.Window', {
		title: "批量导入",
		width: 300,
		height: 150,
		closable: true,
		modal: true,
		headerPosition: 'top',
		items: [fromPanel],
		buttons: [{
			xtype: "button",
			text: "开始导入",
			iconCls: 'icon-save',
			handler: function() {
				var form = fromPanel.getForm();
				var selectProjectId = Ext.getCmp("subProjectStore").getValue();
				if (selectProjectId == "") {
					Ext.MessageBox.alert("系统提示", "请选择项目");
					return;
				}
				if (form.isValid()) {
					var params = form.getValues();
					params.projectId = selectProjectId;
					form.submit({
						url: contextPath + '/marketing/import/subscribeImport',
						params: params,
						method: "POST",
						waitMsg: '正在上传...',
						success: function(form, action) {
							Ext.MessageBox.alert("系统提示", "导入成功");
						},
						failure: function(form, action) {
							var obj = JSON.parse(action.response.responseText);
							var res = obj.res;
							if (res == "1") {
								var result = obj.obj;
								var successCount = result.successCount;
								var errorCount = result.errorCount;
								var totalCount = successCount + errorCount;
								var batchId = result.batchId;
								var showMsg = "总计："
										+ totalCount
										+ "条;成功:"
										+ successCount
										+ "条;失败:"
										+ errorCount
										+ "条;";
								if (errorCount > 0) {
									Ext.MessageBox.confirm("提示", 
										showMsg + ",是否下载错误数据?",
										function(btn, txt) {
											if (btn == "yes") {
												//下载
												var downloadUrl = contextPath
														+ "/customer/import/download?batchId="
														+ batchId + "&type=subscribe";
												location.href = downloadUrl;
											}
										}
									);
								} else {
									Ext.MessageBox.alert("提示", showMsg);
									gridStoreg.load();
								}
							} else {
								Ext.MessageBox.alert("提示", "导入失败");
							}
						}
					});
				}
			}
		},{
			xtype : "button",
			text : "模板下载",
			iconCls : 'icon-save',
			handler : function() {
				var type = fromPanel.getForm().getValues().type;
				console.log(type);
				if(type == "2"){
					location.href = templet_cw;
				} else {
					location.href = templet;
				}
			}
		}]
	});
	window.show();
}
